package com.example.war.kaptcha;

import com.google.code.kaptcha.Constants;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.impl.NoNoise;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha() {
        Properties properties = new Properties();
        properties.put(Constants.KAPTCHA_BORDER, "no");
        properties.put(Constants.KAPTCHA_BORDER_COLOR, "105,179,90");
        properties.put(Constants.KAPTCHA_IMAGE_WIDTH,"110");
        properties.put(Constants.KAPTCHA_IMAGE_HEIGHT,"45");
        properties.put(Constants.KAPTCHA_TEXTPRODUCER_FONT_SIZE,"35");
        properties.put(Constants.KAPTCHA_TEXTPRODUCER_FONT_COLOR, "red");
        //宋体,楷体,微软雅黑
        properties.put(Constants.KAPTCHA_TEXTPRODUCER_FONT_NAMES, "楷体");
        properties.put(Constants.KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");

        properties.put(Constants.KAPTCHA_NOISE_IMPL, NoNoise.class.getName());
        properties.put(Constants.KAPTCHA_OBSCURIFICATOR_IMPL, MyFontStyle.class.getName());

        properties.put(Constants.KAPTCHA_BACKGROUND_IMPL, TranslucentBackground.class.getName());

        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
